#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include"vector.hpp"
#include<algorithm>
void test_vector1()
{
    Mango::vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);

    for (size_t i = 0; i < v.size(); ++i)
    {
        cout << v[i] << " ";//1 2 3 4 5 6
    }
    cout << endl;

    Mango::vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        cout << *it << " ";//1 2 3 4 5 6
        ++it;
    }
    cout << endl;

    for (auto e : v)
    {
        cout << e << " ";//1 2 3 4 5 6
    }
    cout << endl;
}
void test_vector3()
{
    Mango::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    Mango::vector<int> v2(v1);
    for (auto e : v2)
        cout << e << " ";//1 2 3 4
    cout << endl;

    Mango::vector<int> v3;
    v3.push_back(10);
    v3.push_back(20);
    v3.push_back(30);

    v1 = v3;
    for (auto e : v1)
        cout << e << " ";//10 20 30
    cout << endl;
}
void test_vector4()
{
    Mango::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    Mango::vector<int>::iterator it = find(v1.begin(), v1.end(), 2);
    if (it != v1.end())
    {
        // 如果insert中发生了扩容，那么会导致it指向空间被释放
        // it本质就是一个野指针，这种问题，我们就叫迭代器失效
        v1.insert(it, 20);
    }

    for (auto e : v1)
    {
        cout << e << " ";//1 20 2 3 4
    }
    cout << endl;
}
void test_vector5()
{
    // 三种场景去测试
    // 1 2 3 4 5 -> 正常
    // 1 2 3 4   -> 崩溃
    // 1 2 4 5   -> 没删除完
    Mango::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(4);
    v1.push_back(5);

    for (auto e : v1)
        cout << e << " "; //1 2 4 5

    cout << endl;
    // 要求删除v1所有的偶数
    Mango::vector<int>::iterator it = v1.begin();
    while (it != v1.end())
    {
        if (*it % 2 == 0)
            it = v1.erase(it);
        else
            ++it;
    }

    for (auto e : v1)
        cout << e << " "; //1 5
    cout << endl;
}
void test_vector6()
{
    Mango::vector<string> v;
    v.push_back("111111111111111111111111");
    v.push_back("111111111111111111111111");
    v.push_back("1111111111");
    v.push_back("1111111111");
    v.push_back("1111111111");

    for (auto& e : v)
    {
        cout << e << endl;
    }
    cout << endl;
}
void test_vector7()
{
    Mango::vector<int> v{ 1,2,3,4,5 };
    v.push_back(8);
    v.push_back(8);
    v.push_back(8);
    v.push_back(8);
    v.push_back(8);

    Mango::vector<int> v2;
    v2 = v;
    auto it = find(v2.begin(), v2.end(), 2);
    v2.erase(it);
    for (auto x : v2)
        cout << x << " ";
    cout << endl;
}
void test_vector8()
{
    Mango::vector<int> v(2, 3);
    for (auto x : v)
        cout << x << " ";
    cout << endl;
}
int main()
{
    test_vector7();
    return 0;
}